package com.gxa.controller;

import com.gxa.common.base.R;
import com.gxa.domain.dto.ResetPasswordDTO;
import com.gxa.domain.dto.SysUserInfoUpdateDTO;
import com.gxa.domain.dto.SysUserSaveDTO;
import com.gxa.domain.dto.SysUserUpdateDTO;
import com.gxa.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sys_user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    // 查询
    @RequestMapping(value = "/findSysUserByUserId",method = RequestMethod.GET)
    @ResponseBody
    public R findSysUserByUserId(Integer userId){
        return sysUserService.findSysUserByUserId(userId);
    }

    // 添加
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
//    public R save(SysUserSaveDTO sysUserSaveDTO){//普通对象方式接收参数：默认Params
    public R save(@RequestBody SysUserSaveDTO sysUserSaveDTO){//接收是json格式的对象
       return sysUserService.addSysUser(sysUserSaveDTO);
    }

    // 修改
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public R update(@RequestBody SysUserUpdateDTO sysUserUpdateDTO){
        return sysUserService.updateSysUser(sysUserUpdateDTO);
    }
    //修改个人信息
    @RequestMapping(value = "/updateinfo",method=RequestMethod.POST)
    @ResponseBody
    public R updateinfo(@RequestBody SysUserInfoUpdateDTO sysUserInfoUpdateDTO){
        return sysUserService.updateSysUserInfo(sysUserInfoUpdateDTO);
    }

    // 删除
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public R delete(Integer userId){
        return sysUserService.delSysUserByUserId(userId);
    }


    // 修改密码
    @RequestMapping(value = "/updatePassword",method = RequestMethod.POST)
    @ResponseBody
    public R updatePassword(@RequestBody ResetPasswordDTO resetPasswordDTO){
        return sysUserService.updatePassword(resetPasswordDTO);
    }


}
